package com.primeton.whdc.ccms.reportimpl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.primeton.whdc.ccms.reportapi.client.ApicallRecordClient;
import com.primeton.whdc.ccms.reportapi.response.Result;
import com.primeton.whdc.ccms.reportapi.response.ResultGenerator;
import com.primeton.whdc.ccms.reportimpl.entity.CallRecord;
import com.primeton.whdc.ccms.reportimpl.param.ReportRecordTreeVO;
import com.primeton.whdc.ccms.reportimpl.service.IApiCallRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: YunTao.Li
 * @create: 2020-04-15 13:01
 * @description:
 **/
@RestController
public class ApiCallRecordController implements ApicallRecordClient{

    @Autowired
    private IApiCallRecordService apiCallRecordService;

    /***
     * 参数: page,limit,empCode,empName,deptCode,appCode,sysCode
                apiName
                beginDate
                endDate
        查询日报调用列表
     * @return  com.primeton.whdc.ccms.reportimpl.response.Result
     * 创建人: jinyabin
     * 创建时间: 2020/10/19 11:34
     */
    public Result list(long page, long limit, String empCode, String empName, String deptCode, String appCode,
                       String sysCode,
                       String apiName,
                       String beginDate,
                       String endDate) {

        // 构建查询条件
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("page", page);
        condition.put("limit", limit);
        condition.put("empCode", empCode);
        condition.put("empName", empName);
        condition.put("deptCode", deptCode);
        condition.put("appCode", appCode);
        condition.put("sysCode", sysCode);
        condition.put("beginDate", beginDate);
        condition.put("endDate", endDate);
        condition.put("apiName", apiName);

        IPage<CallRecord> callRecordIPage = null;
        try {
            callRecordIPage = apiCallRecordService.getAPICallRecordList(condition);

        } catch (Throwable e) {
            return ResultGenerator.genFailedResult(e.getMessage());
        }
        try {
            System.out.println("*************==========:" + callRecordIPage.getRecords().get(0).toString());
        } catch (Throwable e1) {

        }
        return ResultGenerator.genOkResult(callRecordIPage);
    }

    /***
     * 参数: empCode,deptCode,queryRange
     * @return  com.primeton.whdc.ccms.reportimpl.response.Result
     * 查询日报调用列表
     * 创建人: jinyabin
     * 创建时间: 2020/10/19 11:35
     */
    public Result reportMonth( String empCode,
                               String deptCode,
                               String queryRange) {

        // 构建查询条件
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("empCode", empCode);
        condition.put("qtype", "month");
        condition.put("queryRange", queryRange);
        condition.put("deptCode", deptCode);

        List<ReportRecordTreeVO> repordRecords = null;
        try {
            repordRecords = apiCallRecordService.getReport(condition);

        } catch (Throwable e) {
            return ResultGenerator.genFailedResult(e.getMessage());
        }

        return ResultGenerator.genOkResult(repordRecords);
    }

    /***
     * 参数: empCode,deptCode,queryRange
     * 查询日报调用列表
     * @return  com.primeton.whdc.ccms.reportimpl.response.Result
     * 创建人: jinyabin
     * 创建时间: 2020/10/19 11:36
     */
    public Result reportWeek( String empCode,
                              String deptCode,
                              String queryRange) {

        // 构建查询条件
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("empCode", empCode);
        condition.put("qtype", "week");
        condition.put("queryRange", queryRange);
        condition.put("deptCode", deptCode);

        List<ReportRecordTreeVO> repordRecords = null;
        try {
            repordRecords = apiCallRecordService.getReport(condition);

        } catch (Throwable e) {
            return ResultGenerator.genFailedResult(e.getMessage());
        }

        return ResultGenerator.genOkResult(repordRecords);
    }



}
